//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package templet;

import entity.Table;
import entity.Templet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import xml.DatabaseXml;

public class Code {
    public Code() {
    }
    
    public static void create(Map<String, String> pathMap, Map<String, String> publicMap) {
        String projectTempletPath = (String)pathMap.get("projectTempletPath");
        String tablleTempletPath = (String)pathMap.get("tablleTempletPath");
        String columnTempletPath = (String)pathMap.get("columnTempletPath");
        String xmlPath = (String)pathMap.get("xmlPath");
        String codePath = (String)pathMap.get("codePath");
        Map<String, String> propertyMap = DatabaseXml.readProperty(xmlPath);
        publicMap.putAll(propertyMap);
        List<Table> tableList = DatabaseXml.readDatabaseXml(xmlPath);
        Map<String, String> tableTempletMap = ClientTempletUtil.getTempletList(tablleTempletPath);
        Map<String, String> columnTempletMap = ClientTempletUtil.getTempletList(columnTempletPath);
        List<Templet> list = TempletUtil.getTempletList(projectTempletPath);
        Iterator var13 = list.iterator();
        
        while(true) {
            while(true) {
                while(var13.hasNext()) {
                    Templet t = (Templet)var13.next();
                    System.out.println("处理模板：" + t.getPath() + "   --- " + t.getFileName());
                    String content;
                    if (FileUtil.isTemplatFile(t.getAllPath())) {
                        content = FileUtil.getContent(t.getAllPath());
                        content = ClientTempletUtil.createContentForTable(content, tableTempletMap, tableList);
                        if (t.getFileName().indexOf("[table]") < 0 && t.getFileName().indexOf("[Table]") < 0 && t.getFileName().indexOf("[table2]") < 0 && t.getFileName().indexOf("[Table2]") < 0) {
                            String outPath = ClientTempletUtil.createContent(codePath + "/" + t.getPath() + "/" + t.getFileName(), publicMap);
                            outPath = outPath.replace("(TFILE)", "");
                            content = ClientTempletUtil.createContent(content, publicMap);
                            FileUtil.setContent(outPath, content);
                        } else {
                            Iterator var16 = tableList.iterator();
                            
                            while(var16.hasNext()) {
                                Table table = (Table)var16.next();
                                String outFile = t.getFileName().replace("[table]", table.getName());
                                outFile = outFile.replace("[Table]", Utils.getClassName(table.getName()));
                                outFile = outFile.replace("[Table2]", Utils.getClassName(table.getName2()));
                                outFile = outFile.replace("[table2]", table.getName2());
                                String outContent = ClientTempletUtil.createContent(content, columnTempletMap, table);
                                System.out.println("全局替换符嵌套替换符处理********" + table.getName());
                                outContent = ClientTempletUtil.createContent(outContent, publicMap);
                                outContent = outContent.replace("[table]", table.getName());
                                String outPath = ClientTempletUtil.createContent(codePath + "/" + t.getPath() + "/" + outFile, publicMap);
                                outPath = outPath.replace("(TFILE)", "");
                                FileUtil.setContent(outPath, outContent);
                            }
                        }
                    } else {
                        content = ClientTempletUtil.createContent(codePath + "/" + t.getPath() + "/" + t.getFileName(), publicMap);
                        FileUtil.copyFile(t.getAllPath(), content);
                    }
                }
                
                System.out.println("代码成功生成!");
                return;
            }
        }
    }
}
